#include <iostream>
#include <mutex>
#include <thread>

std::once_flag flag;
int resource;

void init_resource() {
    resource = 77; // 假设这是一项复杂的初始化操作
    std::cout << "Resource initialized.\n";
}

void thread_func() {
    std::call_once(flag, init_resource);
    std::cout << "Resource: " << resource << std::endl;
}

int main() {
    std::thread t1(thread_func);
    std::thread t2(thread_func);
    t1.join();
    t2.join();
    return 0;
}